Object get keys and values method


Posted by Jim on 2022-09-16

Object.keys(object)

  • 回傳 object 裡所有 key 的 array
cont test = {a: 1, b: 2, c: 3};
console.log(Object.keys(test))
//output: [a, b, c]

Object.values(object)

  • 回傳 object 裡所有 value 的 array
cont test = {a: 1, b: 2, c: 3};
console.log(Object.values(test))
//output: [1, 2, 3]

Object.entries(object)

  • 回傳 object 裡所有 [key, value] 的 array
cont test = {a: 1, b: 2, c: 3};
console.log(Object.entires(test))
//output: [[a, 1], [b, 2], [c, 3]]

#javascript #object #Array







Related Posts

ASP.NET Core Web API 入門教學 - 基本上傳檔案

ASP.NET Core Web API 入門教學 - 基本上傳檔案

[SQL] Want to declare a string array variable? Declare a table variable instead.

[SQL] Want to declare a string array variable? Declare a table variable instead.

《鳥哥 Linux 私房菜:基礎篇》Chapter 01 - Linux 是什麼與如何學習

《鳥哥 Linux 私房菜:基礎篇》Chapter 01 - Linux 是什麼與如何學習


Comments